<template>
  <div class="mcontaner">
    <Header></Header>
    <div class="block">
      <el-timeline>
        <el-timeline-item :timestamp="blog.created" placement="top" v-for="(blog, key) in blogs" :key=key>
          <el-card>
            <h4>
              <router-link :to="{ name: 'BlogDetail', params: { blogid: blog.id } }">{{ blog.title }}</router-link>
            </h4>

            <p>{{ blog.description }}</p>
          </el-card>
        </el-timeline-item>

      </el-timeline>

      <el-pagination class="mage" background layout="prev, pager, next" :current-page="currentPage"
        :page-size="pageSize" :total="total" @current-change=page>
      </el-pagination>
    </div>
  </div>
</template>

<script>
import Header from '@/components/Header.vue'
export default {
  name: "Blogs",
  components: { Header },
  data () {
    return {
      blogs: {},
      currentPage: 1,
      total: 0,
      pageSize: 5
    }
  },
  methods: {
    page (currentPage) {
      this.$axios.get("/blogs?currentPage=" + currentPage).then(res => {
        var data = res.data.data
        this.blogs = data.records
        this.currentPage = data.current
        this.pageSize = data.size
        this.total = data.total
      })
    }
  },
  created () {
    this.page(1)
  }
}
</script>

<style scoped>
.block {
  margin: 20px;
}
.mage {
  margin: 0 auto;
}
</style>